﻿@model CustomerModel

<div class="panel panel-default">
    <div class="panel-heading">
        @T("Admin.Customers.Customers.CurrentShoppingCart")
    </div>
    <vc:admin-widget widget-zone="customer_details_shopping_cart_top" additional-data="Model" />
    <div class="panel-body">
        <div id="currentshoppingcart-grid"></div>
    </div>
    <vc:admin-widget widget-zone="customer_details_shopping_cart_bottom" additional-data="Model" />
</div>

<script>
$(document).ready(function () {
    $("#currentshoppingcart-grid").kendoGrid({
        dataSource: {
            transport: {
                read: {
                    url: "@Html.Raw(Url.Action("GetCartList", "Customer", new { customerId = Model.Id, cartTypeId = (int)ShoppingCartType.ShoppingCart }))",
                    type: "POST",
                    dataType: "json",
                    data: addAntiForgeryToken
                },
                destroy: {
                    url: "@Html.Raw(Url.Action("DeleteCart", "Customer", new { customerId = Model.Id }))",
                    type: "POST",
                    dataType: "json",
                    data: addAntiForgeryToken
                }
            },
            schema: {
                data: "Data",
                total: "Total",
                errors: "Errors",
                model: {
                    id: "Id",
                    fields: {
                        ProductName: { editable: false, type: "string" },
                        Quantity: { editable: false, type: "number" },
                        UnitPrice: { editable: false, type: "string" },
                        Total: { editable: false, type: "string" },
                        Store: { editable: false, type: "string" },
                        UpdatedOn: { editable: false, type: "date" },
                    }
                }
            },
            error: function(e) {
                display_kendoui_grid_error(e);
                // Cancel the changes
                this.cancelChanges();
            },
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true
        },
        pageable: {
            refresh: true,
            numeric: false,
            previousNext: false,
            info: false
        },
        editable: {
            confirmation: true,
            mode: "inline"
        },
        scrollable: false,
        columns: [{
            field: "ProductName",
            title: "@T("Admin.CurrentCarts.Product")",
            width:500,
            template: '<a href="@Url.Content("~/Admin/Product/Edit/")#=ProductId#">#:kendo.htmlEncode(ProductName)#</a>' +
                '# if(AttributeInfo && AttributeInfo.length > 0) {# <br />#=AttributeInfo# #} #'
        }, {
            field: "Quantity",
            title: "@T("Admin.CurrentCarts.Quantity")",
            width:200
        },{
            field: "UnitPrice",
            title: "@T("Admin.CurrentCarts.UnitPrice")",
            width:200
        },{
            field: "Total",
            title: "@T("Admin.CurrentCarts.Total")",
            width:200
        },{
            field: "Store",
            title: "@T("Admin.CurrentCarts.Store")",
            width:200
        },{
            field: "UpdatedOn",
            title: "@T("Admin.CurrentCarts.UpdatedOn")",
            width: 200,
            type: "date",
            format: "{0:G}"
        }, {
            command: [
                {
                name: "destroy",
                text: "@T("Admin.Common.Delete")"
            }],
            width: 200
        }]
    });
});
</script>